<?php
$pacth="C:/xampp/htdocs/05_NIV/";
require_once ($pacth.'DataProvider/_DataConfig.php');

class _DataConnection {
	function _DataConnection() {
	}
	function executeSQL($SQLCommand){
		try{
			$_db=new _DataConfig();
	        $dbURL  = $_db->databaseURL;
	        $dbName = $_db->databaseName;
	        $dbUsr  = $_db->databaseUName;
	        $dbPwd  = $_db->databasePWord;
			$_MySQL= new mysqli( $dbURL, $dbUsr, $dbPwd, $dbName );
	        $_MySQL -> query( "SET NAMES 'UTF8'" );
	        $_MySQL -> query( "SET SQL_SAFE_UPDATES=0" );
			$result =  $_MySQL->query($SQLCommand);
	        //if(isset($result->num_rows)?$result->num_rows:false) return $result;
	        if ($_MySQL->errno!=0){
	            $errmsg= "<b style='color:red'>Begin Dataprovider Error:</b><br/>";
	            $errmsg.= "SQLCommand:<span style='color:#FFAC30;'>".$SQLCommand."</span><br/>";
	            $errmsg.= new Exception($_MySQL->error." - <span style='color:#FFAC30;'>".$SQLCommand."</span>", "1");
	            $errmsg.= "<br/><b style='color:red'>End Dataprovider Error</b>";
	            //echo "<a href='JO_00_integration.php?JO_unit=00_Error' style='color:red;' target='_blank'>Click Here To View This Error</a>";
	            //throw new Exception($mysqli->error." - ".$SQLCommand, "1");
	            if(!isset($_SESSION["MYSQL_ERR"])){
	                //session_register("MYSQL_ERR");
	            }
	            $_SESSION["MYSQL_ERR"]=$errmsg;
				echo $errmsg;
	            $_MySQL->close();
	            return null;
	        }
        } catch (Exception $exc) {
            
            $errmsg= "<b style='color:red'>Begin Dataprovider Error:</b><br/>";
            $errmsg.= "SQLCommand:<span style='color:#FFAC30;'>".$SQLCommand."</span><br/>";
            $errmsg.= $exc->getTraceAsString();
            $errmsg.= "<br/><b style='color:red'>End Dataprovider Error</b>";
            //echo "<a href='JO_00_integration.php?JO_unit=00_Error' style='color:red;' target='_blank'>Click Here To View This Error</a>";
            if(!isset($_SESSION["MYSQL_ERR"])){
                //session_register("MYSQL_ERR");
            }
            $_SESSION["MYSQL_ERR"]=$errmsg;
			echo $errmsg;
            $this->_NIVMySQL->close();
            return null;
        }

        $_MySQL->close();
        return $result;
        return null;
    }
	function executeNoneSQL($SQLCommand){
        try {
        	$_db=new _DataConfig();
	        $dbURL  = $_db->databaseURL;
	        $dbName = $_db->databaseName;
	        $dbUsr  = $_db->databaseUName;
	        $dbPwd  = $_db->databasePWord;
			$_MySQL= new mysqli( $dbURL, $dbUsr, $dbPwd, $dbName );
	        $_MySQL -> query( "SET NAMES 'UTF8'" );
	        $_MySQL -> query( "SET SQL_SAFE_UPDATES=0" );
			$result =  $_MySQL->query ($SQLCommand);
            $affected_rows=$_MySQL->affected_rows;//mysql_affected_rows();
            if ($_MySQL->errno!=0){
                $errmsg= "<b style='color:red'>Begin Dataprovider Error:</b><br/>";
                $errmsg.= "SQLCommand:<span style='color:#FFAC30;'>".$SQLCommand."</span><br/>";
                $errmsg.= new Exception($_MySQL->error." - <span style='color:#FFAC30;'>".$SQLCommand."</span>", "1");
                $errmsg.= "<br/><b style='color:red'>End Dataprovider Error</b>";
                //echo "<a href='JO_00_integration.php?JO_unit=00_Error' style='color:red;' target='_blank'>Click Here To View This Error</a>";
                //throw new Exception($mysqli->error." - ".$SQLCommand, "1");
                if(!isset($_SESSION["MYSQL_ERR"])){
                    //session_register("MYSQL_ERR");
                }
                $_SESSION["MYSQL_ERR"]=$errmsg;
				echo $errmsg;
                $_MySQL->close();
                return 0;
            }
        } catch (Exception $exc) {
            $errmsg= "<b style='color:red'>Begin Dataprovider Error:</b><br/>";
            $errmsg.= "SQLCommand:<span style='color:#FFAC30;'>".$SQLCommand."</span><br/>";
            $errmsg.= $exc->getTraceAsString();
            $errmsg.= "<br/><b style='color:red'>End Dataprovider Error</b>";
            //echo "<a href='JO_00_integration.php?JO_unit=00_Error' style='color:red;' target='_blank'>Click Here To View This Error</a>";
            if(!isset($_SESSION["MYSQL_ERR"])){
                //session_register("MYSQL_ERR");
            }
            $_SESSION["MYSQL_ERR"]=$errmsg;
			echo $errmsg;
            $_MySQL->close();
            return 0;
            
        }
        $_MySQL->close();
        return $affected_rows;
    }
}
?>